#!/bin/sh
: ${DEV_DEBUG:=false}
$DEV_DEBUG && set -x

if [ -z "$NETBEANS_DATA" ]; then
	echo "NETBEANS_DATA not set" 1>&2
	exit 1
fi

if [ -z "$NETBEANS_HOME" ]; then
	echo "NETBEANS_HOME not set" 1>&2
	exit 1
fi

case "`uname`" in
	CYGWIN*) _suffix=.exe
	NETBEANS_DATA=`cygpath -aw "$NETBEANS_DATA"`
	;;
	*)
	;;
esac

NETBEANS_EXEC="$NETBEANS_HOME/bin/netbeans${_suffix}"
if [ ! -r "$NETBEANS_EXEC" ]; then
	echo "'$NETBEANS_EXEC' not executable" 1>&2
	exit 1
fi

export JAVA_HOME=${NETBEANS_JAVA_HOME}

if [ ! -x "$NETBEANS_JAVA_HOME/bin/java" ]; then
	echo "'$NETBEANS_JAVA_HOME' is not a JAVA_HOME" 1>&2
	exit 1
fi

nohup "$NETBEANS_EXEC" --jdkhome "$NETBEANS_JAVA_HOME" --userdir "$NETBEANS_DATA" $NETBEANS_OPTS -J-Duser.name="$IDE_AUTHOR" "${@}" >/dev/null 2>&1 &
